// mail/mail.service.ts
import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bull';
import { Queue } from 'bull';

@Injectable()
export class MailService {
  constructor(@InjectQueue('mail') private mailQueue: Queue) {}

  async sendMail(to: string, subject: string, content: string) {
    // 添加任务到队列
    await this.mailQueue.add(
      'send',
      { to, subject, content },
      {
        delay: 1000 * 10,
        // repeat: { cron: '0 8 * * *' }, // 定时任务：每天8点发送（需结合 cron 表达式）

        // // 失败后最多重试3次，每次间隔10秒
        // attempts: 3,
        // backoff: 10000,
      },
    );
  }
}
